package com.zhongxi.guoyuan.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zhongxi.guoyuan.R;
import com.zhongxi.guoyuan.entity.WithDrawResult;

import java.util.List;

/**
 * Created by Administrator on 2017/3/6.
 */

public class WithDrawAdapter extends BaseAdapter {

    private Context context;
    private List<WithDrawResult.WithDrawData> list ;

    public WithDrawAdapter(Context context, List<WithDrawResult.WithDrawData> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_with_draw, parent, false);
            holder.tvTime = (TextView) convertView.findViewById(R.id.tvTime);
            holder.tvCoin = (TextView) convertView.findViewById(R.id.tvCoin);
            holder.tvStatus = (TextView) convertView.findViewById(R.id.tvStatus);
            holder.iv_point = (ImageView) convertView.findViewById(R.id.iv_point);
            holder.linearBackground = (LinearLayout) convertView.findViewById(R.id.linearBackground);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        if(position%2 == 0){
            holder.linearBackground.setBackgroundColor(context.getResources().getColor(R.color.background));
        }else{
            holder.linearBackground.setBackgroundColor(context.getResources().getColor(R.color.background));
        }
        if(null!=list.get(position)&&!"".equals(list.get(position))){
            WithDrawResult.WithDrawData data = list.get(position);
            if(null!=data.getApply_ctime()&&!"".equals(data.getApply_ctime())){
                holder.tvTime.setText(data.getApply_ctime());
            }else{
                holder.tvTime.setText("");
            }
            if(null!=data.getAmount()&&!"".equals(data.getAmount())){
                holder.tvCoin.setText(data.getAmount());
            }else{
                holder.tvCoin.setText("");
            }
            if(null!=data.getStatus()&&!"".equals(data.getStatus())){
                if("1".equals(data.getStatus())){
                    holder.tvStatus.setText("已兑换");
                    holder.iv_point.setVisibility(View.GONE);
                    holder.tvStatus.setTextColor(context.getResources().getColor(R.color.text_color));
                }else if("0".equals(data.getStatus())){
                    holder.tvStatus.setText("受理中");
                    holder.iv_point.setVisibility(View.VISIBLE);
                    holder.tvStatus.setTextColor(context.getResources().getColor(R.color.red));
                }
            }
        }
        return convertView;
    }

    class ViewHolder{
        private TextView tvTime;
        private TextView tvCoin;
        private TextView tvStatus;
        private LinearLayout linearBackground;
        private ImageView iv_point;
    }
}